﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.Core.Common;
using Jzy.Core.Common.Web;

using Jzy.BLL.DocManger;
using Jzy.Model.DocManger;
using Frame.Lib.Utilities;
using Frame.Lib.Core.Right;
using Frame.Lib.Common;


namespace Jzy.Web.DocManager.Document
{
    public partial class DirList : PageList
    {
        private DirBO _dir;
        private DirBO Dir
        {
            get
            {
                if (_dir == null)
                {
                    _dir = new DirBO();
                }
                return _dir;
            }
        }

        private string _dirID;
        private string DirID
        {
            get
            {
                if (_dirID == null)
                {
                    _dirID = this.Decrypt(Request.QueryString["DirID"]);
                }
                return _dirID;
            }
        }



        protected void Page_Load(object sender, EventArgs e)
        {

           

            if (!IsPostBack)
            {
               
                BindView();
               
                lblDirName.Visible = true;
                lblDirName.Text = this.Dir.GetName(DirID) + "&nbsp;";
            }
            
            AddAttr();
            base.InitSelectID(hidSelectIDs);
           
            JSUtil.SetTableHeight("list", 95);

        }


        private void AddAttr()
        {
            

        }

        private void BindView()
        {
            RecordRightBO right = new RecordRightBO("DocDir");

            LVUtil.Init(lv, lvHeader);


            IEnumerable<DirInfo> list = Dir.GetList(int.Parse(DirID), AppSession.UserID, null);

            lblStatistic.Text = "[&nbsp;共<b style='color:red;'> " + list.Count() + "</b>&nbsp;个子目录&nbsp;]";

            lv.DataSource = list;
            lv.DataKeyNames = new string[] { "ID", "CreatorID" };
            lv.DataBind();


        }

       

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            BindView();
        }

        

        protected void lv_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                int id = (int)lv.DataKeys[((ListViewDataItem)e.Item).DataItemIndex]["ID"];

                string strID = StrUtil.EncryptUrl(lv.DataKeys[((ListViewDataItem)e.Item).DataItemIndex]["ID"].ToString());
               

                HyperLink lnkName = (HyperLink)e.Item.FindControl("lnkName");
                lnkName.NavigateUrl = "List.aspx?DirID=" + strID;
                
            }
        }
    }
}
